#include <iostream>
#include <unordered_set>
#include <unordered_map>
#define MAXN 1000005
using namespace std;
int P;
int arrays[MAXN], used[MAXN];
unordered_set<int> ack;
void solve();
int main() {
    cin >> P;
    for (int i = 0; i < P; i++) {
        cin >> arrays[i];
        ack.insert(arrays[i]);
    }
    solve();
}

void solve() {
    int front = 0, res = P;
    unordered_set<int> record;
    for (int i = 0; i < P; i++) {
        used[arrays[i]]++;
        record.insert(arrays[i]);
        while (front < P && used[arrays[front]] > 1) {
            used[arrays[front]]--; front++;
        }
        if (record.size() == ack.size()) {
            res = min(res, i - front + 1);
        } 
    }
    cout << res << endl;
}